﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
@* <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head> *@
<body>

    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <div class="layui-inline">
                        <label class="layui-form-label">销售日期：</label>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="date" id="startSellTime" class="layui-input">
                        </div>-
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="date" id="endSellTime" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">客户</label>
                        <div class="layui-input-block">
                            <select name="city" id="clientId" lay-filter="testSelect">
                                <option value="0">请选择</option>
                                <option value="1">公羊</option>
                                <option value="2">母羊</option>
                                <option value="3">小羊</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">耳号</label>
                        <div class="layui-input-block">
                            <div class="layui-input-inline layui-input-wrap">
                                <input type="date" id="recordAuricle" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">单据号</label>
                        <div class="layui-input-block">
                            <div class="layui-input-inline layui-input-wrap">
                                <input type="date" id="documentNumber" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <label class="layui-form-label">部门</label>
                    <div class="layui-input-block">
                        <select name="city" id="departmentId" lay-filter="testSelect1">
                            <option value="0">请选择</option>
                            <option value="1">张三</option>
                            <option value="2">李四</option>
                            <option value="3">王五</option>
                        </select>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">收货地址</label>
                        <div class="layui-input-block">
                            <div class="layui-input-inline layui-input-wrap">
                                <input type="date" id="deliveryAddress" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <label class="layui-form-label">销售员：</label>
                    <select name="city" id="salesman" lay-filter="testSelect2">
                        <option value="">请选择</option>
                        <option value="张三">张三</option>
                        <option value="李四">李四</option>
                        <option value="王五">王五</option>
                    </select>

                    <div class="layui-inline">
                        <label class="layui-form-label">审核状态</label>
                        <div class="layui-input-block">
                            <select name="city" id="reviewStatus" lay-filter="testSelect3">
                                <option value="0">请选择</option>
                                <option value="1">未审核</option>
                                <option value="2">已审核</option>
                            </select>
                        </div>
                    </div>

                </div>
                <button type="button" class="layui-btn layui-bg-red" id="searchBtn" onclick="Show()">搜索</button>

                <button type="button" class="layui-btn layui-bg-red" onclick="Add()" lay-on="test-iframe-curl">新增</button>

            </div>


        </div>



        <div id="demo-laypage-all"></div>
        <table class="layui-table">
            <thead>
                <tr>
                    <td>序号</td>
                    <td>销售日期</td>
                    <td>单据号</td>
                    <td>客户</td>
                    <td>总成交价</td>
                    <td>审核状态</td>
                    <td>部门</td>
                    <td>收货地址</td>
                    <td>销售员</td>

                    <td>创建人</td>
                    <td>创建时间</td>
                    <td>修改人</td>
                    <td>修改时间</td>

                    <td>审核人</td>
                    <td>审核时间</td>
                    <td>财务审核人</td>
                    <td>财务审核时间</td>
                    <td>仓库审核人</td>
                    <td>审核时间</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody></tbody>
        </table>

    </form>


    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>
    <script>
        function Add() {
            location.href = "/Purchase/AddSellIndex";
        }
        layui.use('form', function () {
            var table = layui.table;
            var form = layui.form;
            var layer = layui.layer;
            var laypage = layui.laypage;
            var pageIndex = 1;
            var pageSize = 5;


            form.on('select(testSelect)', function (data) {
                Show(data.value); // data.value 返回选中的值
            });
            form.on('select(testSelect1)', function (data) {
                Show(data.value); // data.value 返回选中的值
            });
            form.on('select(testSelect2)', function (data) {
                Show(data.value); // data.value 返回选中的值
            });
            form.on('select(testSelect3)', function (data) {
                Show(data.value); // data.value 返回选中的值
            });
            form.on('select(testSelect4)', function (data) {
                Show(data.value); // data.value 返回选中的值
            });





            Show();


            //显示列表
            function Show() {
                var startSellTime = null
                var endSellTime = null
                var clientId = $("#clientId").val()
                var recordAuricle = $("#recordAuricle").val()
                var documentNumber = $("#documentNumber").val()
                var departmentId = $("#departmentId").val()
                var deliveryAddress = $("#deliveryAddress").val()
                var salesman = $("#salesman").val()
                var reviewStatus = $("#reviewStatus").val()
                $.post({
                    url: 'http://localhost:5269/api/SheepSells/SheepSellQuery',
                    data: JSON.stringify({ startSellTime: startSellTime, endSellTime: endSellTime, clientId: clientId, recordAuricle: recordAuricle, documentNumber: documentNumber, departmentId: departmentId, deliveryAddress: deliveryAddress, salesman: salesman, reviewStatus: reviewStatus, pageIndex: pageIndex, pageSize: pageSize }),
                    async: false,
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        var count = "";

                        $.each(res.data, function () {
                            var aa = this.sellTime.split("T")[0];
                            var bb = this.clientId == 0 ? "黄赛超" : this.clientId == 1 ? "李颖" : "崔海瑞";
                            var cc = this.reviewStatus == 1 ? "未审核" : "已审核";
                            var dd = this.departmentId == 0 ? "默认" : this.departmentId == 1 ? "销售部" : "人事部";
                            if (this.createdOwnerId == null) {
                                this.createdOwnerId = ""
                            }
                            if (this.createdTime == null) {
                                this.createdTime = ""
                            }
                            if (this.updatedOwnerId == null) {
                                this.updatedOwnerId = ""
                            }
                            if (this.updatedTime == null) {
                                this.updatedTime = ""
                            }
                            else {
                                this.updatedTime = moment(this.updatedTime).format("YYYY-MM-DD HH:mm:ss")
                            }
                            count += `
                                                <tr>
                                                        <td>${this.sellId}</td>
                                                        <td>${aa}</td>
                                                        <td>${this.documentNumber}</td>
                                                        <td>${bb}</td>
                                                        <td>${this.closingPrice}</td>
                                                        <td>${cc}</td>
                                                        <td>${dd}</td>
                                                        <td>${this.deliveryAddress}</td>
                                                        <td>${this.salesman}</td>

                                                        <td>${this.createdOwnerId}</td>
                                                        <td>${this.createdTime}</td>
                                                        <td>${this.updatedOwnerId}</td>
                                                        <td>${this.updatedTime}</td>
                                                        <td>张三</td>
                                                        <td>2024-12-07</td>
                                                        <td>张三</td>
                                                        <td>2024-12-07</td>
                                                        <td>张三</td>
                                                        <td>2024-12-07</td>
                                                    <td>
                                                            <a onclick="funDel()" class="btn btn-link">删除</a>
                                                                            <a onclick="funDel()" class="btn btn-link" lay-on="test-iframe-curl">编辑</a>
                                                            </td>
                                                        </tr>
                                                        `
                        })
                        //pagedCount = res.pagedCount;
                        //pcount = res.totalCount;
                        $("tbody").html(count)
                        // console.log(res.data)

                        //var page = Math.ceil(res.totalCount / 5);  //总页数
                        console.log(996, pageSize, pageIndex, res);
                        // 完整显示
                        laypage.render({
                            elem: 'demo-laypage-all', // 元素 id
                            curr: pageIndex,//当前页
                            pages: res.pagedCount,    //总页数
                            limit: pageSize,//每页几条
                            limits: [5, 10, 15],
                            count: res.totalCount, // 数据总数
                            layout: ['count', 'prev', 'page', 'first', 'last', 'next', 'limit', 'skip'], // 功能布局
                            jump: function (obj, first) {
                                if (!first) {
                                    console.log(888, obj);
                                    console.log(obj.curr); // 得到当前页，以便向服务端请求对应页的数据。
                                    console.log(obj.limit); // 得到每页显示的条数
                                    pageIndex = obj.curr;
                                    pageSize = obj.limit;
                                    Show();
                                }
                            }
                        });
                    }
                })


            }

        });

    </script>


</body>

</html>